package com.zr.repertory.inventorySettings.mapper;

import com.zr.inventorySettings.pojo.*;
import org.apache.ibatis.annotations.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * Created by Calm on 2019/11/20.
 */
@Mapper
public interface InventoryMapper {

                                            /*库房标示部分*/
    /*验证库房标示编码不能重复*/
    @Select("select count(wareHouseMarkCode) from warehousemark where wareHouseMarkCode=#{warehousemarkcode}")
    int Warehousemarkcode(String warehousemarkcode);
    //验证库房标示名称不能重复
    @Select("select count(wareHouseMarkName) from warehousemark where wareHouseMarkName=#{warehousemarkname} ")
    int queryWarehousemarkname(String warehousemarkname);
    //库房标示新增
    @Insert("insert into WareHouseMark(wareHouseMarkName,wareHouseMarkCode, wareHouseMarkRemark,wareHouseMarkStatus, createName, createTime,updateName, updateTime)" +
            "values(#{warehousemarkname},#{warehousemarkcode}, #{warehousemarkremark},#{warehousemarkstatus}, #{createname}, #{createtime},#{updatename},#{updatetime})")
    void identificationAdd(Warehousemark warehousemark);
    /*库房标示分页查询*/
    int queryIdentificationQueryCount(WarehousemarkSelectVo warehousemarkSelectVo);
    List<Warehousemark> queryIdentificationQueryData(WarehousemarkSelectVo warehousemarkSelectVo);
    /*验证是否存在要修改的库房标识*/
    @Select("select * from warehousemark where wareHouseMarkId=#{warehousemarkid}")
    Warehousemark queryIdentificationById(Integer warehousemarkid);
    //验证库房标识名称是否存在
    @Select("select * from warehousemark where wareHouseMarkName=#{warehousemarkname}")
    Warehousemark queryIdentificationByName(String warehousemarkname);
    //库房标识修改
    @Update("update warehousemark set wareHouseMarkName = #{warehousemarkname},wareHouseMarkRemark = #{warehousemarkremark},wareHouseMarkStatus = #{warehousemarkstatus},updateName = #{updatename},updateTime = #{updatetime}" +
            "where wareHouseMarkId=#{warehousemarkid}")
    int identificationUpdate(Warehousemark warehousemark);
    //库房标示启用/禁用接口
    @Update("update warehousemark set wareHouseMarkStatus = #{warehousemarkstatus},updateName = #{updatename},updateTime = #{updatetime} where wareHouseMarkId=#{warehousemarkid}")
    void identificationUpdateStatus(Warehousemark warehousemark);

                                             /*库房部分*/
    /*库房新增前验证*/
    @Select("select count(wareHouseCode) from warehouse where wareHouseCode=#{warehousecode}")
    int Warehousecode(String warehousecode);
    @Select("select count(wareHouseName) from warehouse where wareHouseName=#{warehousename}")
    int queryWarehousename(String warehousename);
    /*新增接口*/
    @Insert("insert into warehouse(wareHouseName,wareHouseCode,wareHouseAddressA,wareHouseAddressB,wareHouseStatus,wareHouseRemark,wareHouseMarkId,createName,createTime,updateName,updateTime)" +
            "values(#{warehousename},#{warehousecode},#{warehouseaddressa},#{warehouseaddressb},#{warehousestatus},#{warehouseremark},#{warehousemarkid},#{createname},#{createtime},#{updatename},#{updatetime})")
    void roomAdd(Warehouse warehouse);
    /*库房分页*/
    int queryRoomQuerypageCount(WarehouseSelectVo warehouseSelectVo);
    List<Warehouse> queryRoomQuerypageData(WarehouseSelectVo warehouseSelectVo);
    /*库房修改前验证*/
    /*验证是否存在要修改的库房*/
    @Select("select * from warehouse where wareHouseId=#{warehouseid}")
    Warehouse queryRoomById(Integer warehouseid);
    /*验证库房名称是否存在*/
    @Select("select * from warehouse where wareHouseName=#{warehousename}")
    Warehouse queryRoomByName(@NotBlank(message = "库房名称不能为空") String warehousename);
    /*修改库房接口*/
    @Update("update warehouse set wareHouseName = #{warehousename},wareHouseRemark = #{warehouseremark},wareHouseStatus = #{warehousestatus},updateName = #{updatename},updateTime = #{updatetime}" +
            "where wareHouseId=#{warehouseid}")
    int roomUpdate(Warehouse warehouse);
    /*库房启用/禁用接口*/
    @Update("update warehouse set wareHouseStatus = #{warehousestatus},updateName = #{updatename},updateTime = #{updatetime} where wareHouseId=#{warehouseid}")
    void roomUpdateStatus(Warehouse warehouse);

                                                /*
                                                    库区属性部分
                                                */
    /*库区新增前验证*/
    /*验证库区属性编码不能重复*/
    @Select("select count(reservoirPropertiesCode) from reservoirareaproperties where reservoirPropertiesCode=#{reservoirpropertiescode}")
    int Attributecode(String reservoirpropertiescode);
    /*验证库区属性名称不能重复*/
    @Select("select count(reservoirPropertiesName) from reservoirareaproperties where reservoirPropertiesName=#{reservoirpropertiesname}")
    int Attributename(String reservoirpropertiesname);
    //新增接口
    @Insert("insert into reservoirareaproperties(reservoirPropertiesName,reservoirPropertiesCode,reservoirPropertiesRemark,reservoirPropertiesStatus)" +
            "values(#{reservoirpropertiesname},#{reservoirpropertiescode},#{reservoirpropertiesremark},#{reservoirpropertiesstatus})")
    void AttributeAdd(ReservoirareapropertiesAddVo reservoirareapropertiesAddVo);
    /*库区属性分页*/
    int queryAttributeQuerypageCount(ReservoirareapropertiesSelectVo reservoirareapropertiesSelectVo);
    List<Reservoirareaproperties> queryAttributeQuerypageData(ReservoirareapropertiesSelectVo reservoirareapropertiesSelectVo);
    /*库区属性修改前验证*/
    /*验证是否存在要修改的库区属性*/
    @Select("select * from reservoirareaproperties where reservoirPropertiesId=#{reservoirpropertiesid}")
    Reservoirareaproperties queryAttributeById(Integer reservoirpropertiesid);
    /*验证库区属性名称是否存在*/
    @Select("select * from reservoirareaproperties where reservoirPropertiesName=#{reservoirpropertiesname}")
    Reservoirareaproperties queryAttributeByName(String reservoirpropertiesname);
    /*库区属性修改接口*/
    @Update("update reservoirareaproperties set reservoirPropertiesName = #{reservoirpropertiesname},reservoirPropertiesCode = #{reservoirpropertiescode},reservoirPropertiesRemark = #{reservoirpropertiesremark},reservoirPropertiesStatus = #{reservoirpropertiesstatus}" +
            "where reservoirPropertiesId=#{reservoirpropertiesid}")
    void attributeUpdate(ReservoirareapropertiesUpdateVo reservoirareapropertiesUpdateVo);
    /*库区属性启用/禁用接口*/
    @Update("update reservoirareaproperties set reservoirPropertiesStatus = #{reservoirpropertiesstatus} where reservoirPropertiesId=#{reservoirpropertiesid}")
    void attributeUpdateStatus(Reservoirareaproperties reservoirareaproperties);

                                                    /*
                                                        库区部分
                                                  */
    /*库房编码下拉框接口*/
    @Select("select * from warehouse")
    List<Warehouse> roomXiala();
    /*库区新增前验证*/
    @Select("select count(reservoirAreaCode) from reservoirarea where reservoirAreaCode=#{reservoirareacode}")
    int Roomareacode(String reservoirareacode);
    @Select("select count(reservoirAreaName) from reservoirarea where reservoirAreaName=#{reservoirareaname}")
    int Roomareaname(String reservoirareaname);
    /*库区新增接口*/
    void roomareaAdd(ReservoirareaAddVo reservoirareaAddVo);
    void roomareaAdd2(ReservoirareaAddVo reservoirareaAddVo);
    /*库区分页接口*/
    int queryRoomareaQueryCount(ReservoirareaSelectVo reservoirareaSelectVo);
    List<Reservoirarea> queryRoomareaQueryData(ReservoirareaSelectVo reservoirareaSelectVo);
    /*库区修改前验证*/
    /*验证是否存在要修改的库区*/
    @Select("select * from reservoirarea where reservoirAreaId=#{reservoirareaid}")
    Reservoirarea queryRoomareaById(Integer reservoirareaid);
    /*验证库区名称是否存在*/
    @Select("select * from reservoirarea where reservoirAreaName=#{reservoirareaname}")
    Reservoirarea queryRoomareaByName(String reservoirareaname);
    /*库区修改接口*/
    void roomareaUpdate(ReservoirareaUpdateVo reservoirareaUpdateVo);
    void roomareaUpdate2(ReservoirareaUpdateVo reservoirareaUpdateVo);
    /*修改前删除中间表旧数据*/
    @Delete("delete from reservoirareaandreservoirareaproperties where reservoirAreaId=#{reservoirareaid}")
    void delRoomarea2(ReservoirareaUpdateVo reservoirareaUpdateVo);
    /*库区查看接口*/
    @Select("SELECT rr.* FROM reservoirarea r LEFT JOIN reservoirareaandreservoirareaproperties rar on r.reservoirAreaId=rar.reservoirAreaId" +
            "LEFT JOIN reservoirareaproperties rr  ON rar.reservoirPropertiesId=rr.reservoirPropertiesId" +
            "where r.reservoirAreaId=#{reservoirareaid}")
    List<Reservoirareaproperties> queryRoomareaProperties(Integer reservoirareaid);
    /* 库区启用/禁用接口*/
    @Update("update reservoirarea set reservoirAreaStatus = #{reservoirareastatus} where reservoirAreaId=#{reservoirareaid}")
    void roomareaUpdateStatus(Reservoirarea reservoirarea);

                                                /*
                                                    库位部分
                                                */
    /*库区编码下拉框接口*/
    @Select("select * from reservoirarea where wareHouseId=#{warehouseid}")
    List<Reservoirarea> queryByWarehouseId(Integer warehouseid);
    /*根据库区编码展示原有的库位信息*/
    @Select("select * from storagelocation where reservoirAreaId=#{reservoirareaid}")
    List<Storagelocation> queryByReservoirareaId(Integer reservoirareaid);
    /*库区新增前验证*/
    //验证库区是否存在
    @Select("select count(reservoirAreaId) from storagelocation where reservoirAreaId=#{reservoirareaid}")
    int reservoirareaBycode(Integer reservoirareaid);
    //验证库位编码是否重复
    @Select("select count(storageLocationCode) from storagelocation where storageLocationCode=#{storagelocationcode}")
    int RoomSpaceecode(String storagelocationcode);
    //验证库位名称是否重复
    @Select("select count(storageLocationName) from storagelocation where storageLocationName=#{storagelocationname}")
    int RoomSpacename(String storagelocationname);
    /*库位新增接口*/
    //添加前删除库位中原有的内容
    @Delete("delete from storagelocation where reservoirAreaId =#{reservoirareaid}")
    void roomSpaceDel(StoragelocationAddVo storagelocationAddVo);
    //将库位表中的新内容入库
    /*@Insert("insert into storagelocation(storageLocationName,storageLocationCode,storageLocationStatus,reservoirAreaId)" +
            "values(#{storagelocationname},#{storagelocationcode},#{storagelocationstatus},#{reservoirareaid})")*/
    void roomSpaceAdd(StoragelocationAddVo storagelocationAddVo);
    /*库位分页查询接口*/
    int queryRoomSpaceQueryCount(StoragelocationSelectVo storagelocationSelectVo);
    List<Storagelocation> queryRoomSpaceQueryData(StoragelocationSelectVo storagelocationSelectVo);
    /*库位修改前验证*/
    @Select("select * from storagelocation where storageLocationName = #{storagelocationname}")
    Storagelocation queryRoomSpaceByName(String storagelocationname);
    /*库位修改接口*/
    @Update("update storagelocation set storageLocationName= #{storagelocationname} where storageLocationId=#{storagelocationid}")
    void roomSpaceUpdate(StoragelocationUpdateVo storagelocationUpdateVo);
    //验证是否存在要修改的库位
    @Select("select * from storagelocation where storageLocationId=#{id}")
    Storagelocation queryRoomSpaceById(Integer id);
    /* 库位启用/禁用接口*/
    @Update("update storagelocation set storageLocationStatus = #{storagelocationstatus} where storageLocationId=#{storagelocationid}")
    void roomSpaceUpdateStatus(Storagelocation storagelocation);
                                                    /*
                                                        库房归属部分
                                                       */
    /*库房归属分页查询接口*/
    int queryBelongQueryCount(DeoptBelongVo deoptBelongVo);
    List<DeoptBelong> queryBelongQueryData(DeoptBelongVo deoptBelongVo);
    /*库房归属查看接口*/
    DeopBelongSeeVo see(Integer legalPersonId);
    /*多条件查询库房的信息*/
    List<Warehouse> queryAllWareHouse(WarehouseSelectVo warehouseSelectVo);
    /*根据勾选的库房信息查库区信息*/
    List<Reservoirarea> queryReservoirarea(Integer warehouseid);
    /*根据勾选的库区信息查库位信息*/
    List<Storagelocation> queryStoragelocation(Integer reservoirareaid);
    /*根据法人查对应的库位库区库房信息*/
    DeopBelongSeeVo queryStoragelocationAndLegalPerson(Integer legalPersonId);
   /* *//*根据库位信息查对应的库区信息*//*
    List<Reservoirarea> queryReservoirareaAndLegalPerson(Integer storagelocationid);
    *//*根据库区信息查对应的库房信息*//*
    List<Warehouse> queryWarehouseAndLegalPerson(Integer reservoirareaid);*/
    /*根据库区属性下拉框查库区信息*/
    List<Reservoirarea> queryReservoirPropertiesAndReservoir(Integer reservoirPropertiesId);
    /*库房归属新增前验证*/
    //验证法人是否存在
    @Select("select count(legalPersonId) from legalpersonandstoragelocation where legalPersonId=#{legalpersonid}")
    int reserbelongingsById(Integer legalpersonid);
    @Delete("delete from legalpersonandstoragelocation where legalPersonId=#{legalpersonid}")
    void delLegalpersonandstoragelocation(Integer legalpersonid);
    /*库房归属新增*/
    void addLegalpersonandstoragelocation(Legalpersonandstoragelocation legalpersonandstoragelocation);
}
